﻿using Microsoft.AspNetCore.Mvc;
using MVC_System.DTO;
using MVC_System.DTO.GualityGroup;
using Newtonsoft.Json;
using WMS_MAV;

namespace MVC_System.Controllers
{
    public class GualityGroupController : Controller
    {
        private readonly  IConfiguration _configuration;
        public GualityGroupController(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        public IActionResult GualityGroupShow()
        {
            return View();
        }
        public async Task<ActionResult> LedgerInfoShow(GualityGroupShowDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "HysSwagger/api/GualityGroup/GetGualityGroup?pageindex=" + dto.pageindex + "&pagesize=" + dto.pagesize + "&gualityGroupNumbering=" + dto.gualityGroupNumbering + "&gualityGroupName=" + dto.gualityGroupName;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        public async Task<ActionResult> GualityGroupSelect(BaseDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"]+ "HysSwagger/api/GualityGroup/GetGualityGroupSelect";
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        public async Task<ActionResult> GualityGroupAdd(GualityGroupAddDTO dto)
        { 
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"]+ "HysSwagger/api/GualityGroup/AddGualityGroup";
            var respomse = await client.PostAsync(url,dto.Data);
            return Json(respomse);
        }
        public async Task<ActionResult> GualityGroupDelete(GualityGroupDeleteDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"]+ "HysSwagger/api/GualityGroup/DeleteGualityGroup";
            var respomse = await client.PostAsync(url,dto.Data);
            return Json(respomse);
        }
        public async Task<ActionResult> GualityGroupModel(GualityGroupModelDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "HysSwagger/api/GualityGroup/ModelGualityGroup?gualityGroupId=" + dto.gualityGroupId;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        public async Task<ActionResult> GualityGroupUpdate(GualityGroupUpdateDTO obj1, string token)
        {

            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "HysSwagger/api/GualityGroup/UpdateGualityGroup";
            string list = JsonConvert.SerializeObject(obj1);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
    }
}
